package ServerStuff;

import java.net.HttpURLConnection;

import javax.mail.MessagingException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Utilities.EmailClient;

import ExceptionClasses.CantAccessEmailException;

@WebServlet("/SendEmailServlet")
public class SendEmailServlet extends HttpServlet
{
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) 
	{
		String content = request.getParameter("content");
		String to = request.getParameter("to");
		String business = (String) request.getSession().getAttribute("username");
		
		try {
			EmailClient client = new EmailClient(business);
			client.sendEmail(to, content);
		} 
		catch (CantAccessEmailException e) {
			e.printStackTrace();
		}
		catch (MessagingException e) {
			e.printStackTrace();
		}
		
		response.setStatus(HttpURLConnection.HTTP_ACCEPTED);
	}
}
